/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-05-25
 * Time: 18:56
 */
public class MyLinkedList {

    private ListNode head ;
    private ListNode last ;
    static class ListNode{
        private int key ;
        private ListNode prev ;
        private ListNode next ;
        public ListNode(int data){
            this.key = data ;
        }
    }
public void disPlay(){
        ListNode cur = this. head ;
        while(cur != null){
            System.out.println(cur.key + "  ");
         cur = cur.next ;
        }
    System.out.println();
}
public int size(){
        ListNode cur = this.head ;
        int count = 0 ;
        while(cur != null){
            cur = cur.next ;
            count ++ ;
        }
        return count ;
}
 //2、无头双向链表实现

        //头插法
        public void addFirst(int data){
        ListNode node = new ListNode(data);
        if(head == null){
            head = last = node ;
            node.next = null ;
        }
        if(head.next == null){
            node.prev = head ;
            node.next = null ;
            head.next = node ;
            last = node ;

        }
        node.next = head .next ;
        node.prev = head  ;
        head.next.prev = node ;
        head.next = node ;

        }
        //尾插法
        public void addLast(int data){}
        //任意位置插入,第一个数据节点为0号下标
        public void addIndex(int index,int data){}
        //查找是否包含关键字key是否在单链表当中
        public boolean contains(int data){
        if(this.head == null){
            return false ;
        }
        ListNode cur = this.head ;
        while(cur != null){
            if(cur.key == data){
                return true ;
            }
        }
        return false ;

        }
        //删除第一次出现关键字为key的节点
        public void remove(int key){}
        //删除所有值为key的节点
        public void removeAllKey(int key){}

        public void clear(){
        this.head = null ;
        this.last = null ;
        }
    }



